class serve extends eui.Component implements eui.UIComponent {
	public constructor(father) {
		super();
		this.skinName = "serveSkin";
		this.father = father;
		//控制球无限循环动画
		var timer1 = new egret.Timer(1000, 0);
		timer1.addEventListener(egret.TimerEvent.TIMER, this.timerStart, this);
		timer1.start();

		var timer2 = new egret.Timer(5000, 0);
		timer2.addEventListener(egret.TimerEvent.TIMER, this.timernum, this);
		timer2.start();

		var timer3 = new egret.Timer(6000, 1);
		timer3.addEventListener(egret.TimerEvent.TIMER, this.timerend, this);
		timer3.start();
	}
	private serve1;
	private serve2;
	private serve3;
	private serve4;
	private index2;
	//摇一摇
	public pro;
	public father;

	protected partAdded(partName: string, instance: any): void {
		super.partAdded(partName, instance);
	}


	protected childrenCreated(): void {
		super.childrenCreated();

		this.serve3.play(-1);
		this.serve1.play(-1);
		this.serve2.play(-1);
		this.pro.value = 10;

		if (window && window["DeviceMotionEvent"]) {
			var second = 3000;//秒
			var starttime = egret.getTimer();//开始时间
			var startX, startY, startZ, endX, endY, endZ;//开始坐标和结束坐标
			startX = startY = startZ = endX = endY = endZ = 0;
			window.addEventListener('devicemotion', (e) => {
				var acceleration = e.accelerationIncludingGravity;//
				var endtime = egret.getTimer();//结束时间
				if ((endtime - starttime) > 100) {
					var diffTime = endtime - starttime;//时间差
					startX = acceleration.x;
					startY = acceleration.y;
					startZ = acceleration.z;
					var speed = Math.abs(startX + startY + startZ - endX - endY - endZ) / diffTime * 10000;
					if (speed > second) {
						this.pro.value += 1;
						//这里就可以写你的操作了,如摇一摇抽奖,换个背景图等,不解释了
					}
					starttime = endtime;
					endX = startX;
					endY = startY;
					endZ = startZ;
				}
			}, false);
			
		} else {
			alert('不支持传感器事件');
		}
	}

	//控制球无限循环动画
	timerStart() {
		this.serve1.play(0);
		this.serve2.play(0);
	}
	timernum() {
		this.serve4.play();
		this.serve2.stop();
	}
	timerend() {
		sceneManager.fun().loading(this.father, game, "game",{
			"pro":this.pro.value
		});

	}



}